<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">制定团建活动计划</div>
      </div>
      <!--  -->
      <div class="x-pro-list" v-for="(item,index) in prodata" :key="item.key">
        <div class="x-pro-top">团建活动计划计划{{index+1}}</div>
        <div class="x-pro-row">
          <div class="x-pro-label">团建主题:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.title" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">团建时间:</div>
          <div class="x-pro-input">
            <el-date-picker v-model="item.times" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" :disabled="isfromindex" :editable="notkey"></el-date-picker>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">参加人:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.person" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">团建形式简述:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.way" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">团建意义简述:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.content" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">负责人:</div>
          <div class="x-pro-input">
            <el-select v-model="item.liable_memberid" placeholder="请选择" :disabled="isfromindex">
              <el-option v-for="item in perdata" :key="item.id" :label="item.username" :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
        <div class="x-pro-remove" @click="removeentrywork(index)" v-show="!isfromindex">删除</div>
      </div>
      <!--  -->
      <div class="x-pro-addbox" @click="goonentrywork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加团建活动计划</div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    var tdate = api.pageParam.date;

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          curId:0,
          tabsdata:[],
          thdate:'',
          deptid:'',
          prodata:[],
          isfromindex:false,
          positiondata:'',//职位
          notkey:false,
          entryworkindex:0,
          onlyfirst:true,
          perdata:'',

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.thdate = tdate;
        that.getperson()
        that.backshow()


      },
      methods: {
        //人
        getperson:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/list',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.perdata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        backshow:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/meeting/getMonthTeambuild',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.thdate
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  that.prodata = ret.data.list;
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //删除
        removeentrywork:function(index){
          let that = this;
          var nowin = index;
          console.log(JSON.stringify(that.prodata));
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.prodata.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.prodata));
            }
          });
        },
        //继续添加
        goonentrywork:function(){
          var that = this;
          that.entryworkindex++
          that.prodata.push({
            'title':'',
            'times':'',
            'person':'',
            'way':'',
            'content':'',
            'liable_memberid':'',
            'index':that.entryworkindex,
          });
        },
        //提交
        isok:function(){
          var that = this;
          console.log(JSON.stringify(that.prodata));
          api.ajax({
            url:baseurl+'api/meeting/addMonthTeambuild',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.thdate,
                all_json:that.prodata

              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.alert({
                    title: '提交成功',
                    msg: '',
                }, function(ret, err) {

                });

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
